package ui.faces.management.renderer
{
	import events.GestureEvent;
	
	import flash.text.TextField;
	
	import global.Managers;
	
	import ui.components.Button;
	import ui.components.renderlist.AbstractRenderer;
	import ui.faces.management.vo.ApplyPayRendererVO;
	import ui.prompt.PromptBox;
	
	import utils.StringUtil;
	import utils.TextUtil;

	public class ApplyPayRenderer extends AbstractRenderer
	{
		private var _txtInfo				: TextField;
		private var _btnConfirm				: Button;
		
		public function ApplyPayRenderer()
		{
			super();
		}
		override protected function createBg():void {
			super.createBg();
			
			with(_bg.graphics) {
				lineStyle(1);
				beginFill(0xffffff, 1);
				drawRect(0, 0, 600, 40);
				endFill();
			}
		}
		override protected function createView():void {
			super.createView();
			
			_txtInfo = TextUtil.getTextFieldEasy("");
			_txtInfo.x = 5;
			_txtInfo.y = 10;
			addChild(_txtInfo);
			
			_btnConfirm = new Button(0, Managers.languageManager.getLanguageText("confirm_pay"), 80, 30, "", confirmPayHandler);
			_btnConfirm.x = 510;
			_btnConfirm.y = 5;
			_btnConfirm.addListener(Managers.faceManager.managementFace);
			addChild(_btnConfirm);
		}
		override protected function updateView():void {
			super.updateView();
			
			var listVO:ApplyPayRendererVO = _listVO as ApplyPayRendererVO;
			var price:Number = 0;
			for each(var dishID:int in listVO.disheIDs) {
				price += Managers.dishManager.getValueByID(dishID).price;
			}
			_txtInfo.text = StringUtil.format(Managers.languageManager.getLanguageText("apply_pay_attention"), listVO.tableID, price);
		}
		private function confirmPayHandler(event:GestureEvent):void {
			var listVO:ApplyPayRendererVO = _listVO as ApplyPayRendererVO;
			var confirm:String = StringUtil.format(Managers.languageManager.getLanguageText("apply_pay_confirm_tip"), listVO.tableID);
			PromptBox.confirm(confirm, "",function():void {
				Managers.serverManager.send("PayBill", {id:listVO.tableID});
			});
		}
	}
}